package com.cloudbroker.bcs.platform.dav.middle.bizservice.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cloudbroker.bcs.common.util.VOUtil;
import com.cloudbroker.bcs.common.util.ValueUtil;
import com.cloudbroker.bcs.platform.dav.bizapi.service.common.stock.StockBizService;
import com.cloudbroker.bcs.platform.dav.bizapi.service.common.stock.result.StockDetailResult;
import com.cloudbroker.bcs.platform.dav.bizapi.service.common.stock.result.StockListResult;
import com.cloudbroker.bcs.platform.dav.bizapi.service.viewpoint.vo.StockCodeForm;
import com.cloudbroker.bcs.platform.dav.bizapi.service.viewpoint.vo.StockListForm;
import com.cloudbroker.bcs.platform.dav.common.config.ConfigValues;
import com.cloudbroker.bcs.platform.dav.middle.entity.Stkcode;
import com.cloudbroker.bcs.platform.dav.middle.entityview.StockListView;
import com.cloudbroker.bcs.platform.dav.middle.extservice.itn.service.ITNService;
import com.cloudbroker.bcs.platform.dav.middle.service.StkcodeService;

/**
 * Created by zhaojp18008 on 2016/5/11.
 */
@Service
public class StockBizServiceImpl implements StockBizService {
    
    @Resource
    private StkcodeService stkcodeService;
    
    @Resource
    private ITNService iTNService;
    
    @Override
    public StockListResult funcStockList(StockListForm form) {
        String stock_code = form.getStock_code();
        Integer request_num = ValueUtil.getInt(form.getRequest_num(), ConfigValues.getRequestNum());
//        Map<String, Object> param = new HashMap<String, Object>();
//        param.put("prod_code", stock_code);//产品代码(支持股票代码和股票中文拼音缩写)
//        param.put("en_finance_mic", "SS.ESA,SS.ESB,SZ.ESA,SZ.ESB");//交易所识别码集合
//        param.put("data_count", request_num);//数据个数
//        return VOUtil.setSuccessResult(iTNService.queryStockListWizard(param));
        StockListResult res = new StockListResult();
        List<StockListView> list = stkcodeService.qryStockList(stock_code, request_num);
        res.newDataList().addAll(list);
        return VOUtil.setSuccessResult(res);
    }
    
    @Override
    public StockDetailResult checkStockCode(StockCodeForm param) {
        StockDetailResult stockDetailResult = new StockDetailResult();
        String stock_code = param.getStock_code();
        Stkcode stkcode = stkcodeService.findByCode(stock_code);
        if (null != stkcode) {
            stockDetailResult.setStock_code(stkcode.getSecu_code());
            stockDetailResult.setChi_name(stkcode.getChi_name());
        } else {
            stockDetailResult.setStock_code("");
            stockDetailResult.setChi_name("");
        }
        
        return VOUtil.setSuccessResult(stockDetailResult);
    }
}
